package com.etc.ser.extenal;

import java.io.*;
import java.util.Objects;

/**
 * @author: knowno
 * @create: 2024-09-12 09:02
 * @Version 1.0
 **/
public class User implements Externalizable {

    public static final long serialVersionUID = 1L;
    private transient String id;
    private String username;
    private String userpass;

    @Override
    public void writeExternal(ObjectOutput out) throws IOException {
        out.writeUTF(username);
        out.writeUTF(userpass);
        out.close();
    }

    @Override
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {

        System.out.println(in.readUTF());
        System.out.println(in.readUTF());
        in.close();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return Objects.equals(id, user.id) && Objects.equals(username, user.username) && Objects.equals(userpass, user.userpass);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, username, userpass);
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                ", username='" + username + '\'' +
                ", userpass='" + userpass + '\'' +
                '}';
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUserpass() {
        return userpass;
    }

    public void setUserpass(String userpass) {
        this.userpass = userpass;
    }

    public User() {
    }

    public User(String id, String username, String userpass) {
        this.id = id;
        this.username = username;
        this.userpass = userpass;
    }
}
